package edu.xust.service.impl;

import edu.xust.config.Resource;
import edu.xust.config.Service;
import edu.xust.dao.PsManagerDao;
import edu.xust.dao.PsOrderDao;
import edu.xust.dto.BaseDto;
import edu.xust.dto.MessageEnum;
import edu.xust.entity.PsManager;
import edu.xust.page.PageInfo;
import edu.xust.service.PsManagerService;

import java.util.List;
import java.util.Optional;

@Service("psManagerService")
public class PsManagerServiceImpl implements PsManagerService {
    @Resource
    PsManagerDao psManagerDao;
    @Resource
    PsOrderDao psOrderDao;


    @Override
    public BaseDto getPsManagerByPage(PageInfo pageInfo) throws Exception {
        List<PsManager> psManagers = psManagerDao.getPsManagerByPage(pageInfo);
        Optional<List<PsManager>> op = Optional.ofNullable(psManagers);
        MessageEnum messageEnum = op.isPresent() ? MessageEnum.GETALLSTUDENTSUCCESS : MessageEnum.GETSTUDENTBYIDFAIL;//如果成立 赋值 赋？与：之间 否则：之后
        BaseDto dto = new BaseDto(messageEnum, op.get());
        dto.setObj(pageInfo);
        return dto;
    }

    @Override
    public BaseDto addPsManager(PsManager psManager) {
        int i = psManagerDao.addPsManager(psManager);
        MessageEnum messageEnum = i > 0 ? MessageEnum.GETALLSTUDENTSUCCESS : MessageEnum.GETSTUDENTBYIDFAIL;
        return new BaseDto(messageEnum);
    }

    @Override
    public BaseDto updatePsManager(PsManager psManager) {
        int i = psManagerDao.updatePsManager(psManager);
        MessageEnum messageEnum = i > 0 ? MessageEnum.GETALLSTUDENTSUCCESS : MessageEnum.GETSTUDENTBYIDFAIL;
        return new BaseDto(messageEnum);
    }

    public BaseDto getPsManagerByPid(String pid) {
        PsManager psm = psManagerDao.getPsManagerByPid(pid);
        MessageEnum messageEnum = psm != null ? MessageEnum.GETALLSTUDENTSUCCESS : MessageEnum.GETSTUDENTBYIDFAIL;
        return new BaseDto(messageEnum, psm);
    }

}
